home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2005 October / PCWOCT05.iso / Software / FromTheMag / The GIMP 2.2.8 / gimp-2.2.8-i586-setup.exe / {app} / share / gimp / 2.0 / scripts / beveled-pattern-arrow.scm < prev    next >
Encoding:
Text File  |  2005-06-30  |  5.2 KB  |  158 lines

  1. ; The GIMP -- an image manipulation program
  2. ; Copyright (C) 1995 Spencer Kimball and Peter Mattis
  3. ;
  4. ; Beveled pattern arrow for web pages
  5. ; Copyright (C) 1997 Federico Mena Quintero
  6. ; federico@nuclecu.unam.mx
  7. ;
  8. ; This program is free software; you can redistribute it and/or modify
  9. ; it under the terms of the GNU General Public License as published by
  10. ; the Free Software Foundation; either version 2 of the License, or
  11. ; (at your option) any later version.
  12. ;
  13. ; This program is distributed in the hope that it will be useful,
  14. ; but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16. ; GNU General Public License for more details.
  17. ;
  18. ; You should have received a copy of the GNU General Public License
  19. ; along with this program; if not, write to the Free Software
  20. ; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21.  
  22.  
  23. (define (script-fu-beveled-pattern-arrow size orientation pattern)
  24.  
  25.   ; define some local helper functions
  26.   (define (map proc seq)
  27.     (if (null? seq)
  28.         '()
  29.         (cons (proc (car seq))
  30.               (map proc (cdr seq)))))
  31.  
  32.   (define (for-each proc seq)
  33.     (if (not (null? seq))
  34.         (begin
  35.           (proc (car seq))
  36.           (for-each proc (cdr seq)))))
  37.  
  38.   (define (make-point x y)
  39.     (cons x y))
  40.  
  41.   (define (point-x p)
  42.     (car p))
  43.  
  44.   (define (point-y p)
  45.     (cdr p))
  46.  
  47.   (define (point-list->double-array point-list)
  48.     (let* ((how-many (length point-list))
  49.            (a (cons-array (* 2 how-many) 'double))
  50.            (count 0))
  51.       (for-each (lambda (p)
  52.                   (aset a (* count 2) (point-x p))
  53.                   (aset a (+ 1 (* count 2)) (point-y p))
  54.                   (set! count (+ count 1)))
  55.                 point-list)
  56.       a))
  57.  
  58.   (define (rotate-points points size orientation)
  59.     (map (lambda (p)
  60.            (let ((px (point-x p))
  61.                  (py (point-y p)))
  62.              (cond ((= orientation 0) (make-point px py))           ; right
  63.                    ((= orientation 1) (make-point (- size px) py))  ; left
  64.                    ((= orientation 2) (make-point py (- size px)))  ; up
  65.                    ((= orientation 3) (make-point py px)))))        ; down
  66.          points))
  67.  
  68.   (define (make-arrow size offset)
  69.     (list (make-point offset offset)
  70.           (make-point (- size offset) (/ size 2))
  71.           (make-point offset (- size offset))))
  72.  
  73.   ; the main function
  74.  
  75.   (let* ((img (car (gimp-image-new size size RGB)))
  76.          (background (car (gimp-layer-new img size size RGB-IMAGE "Arrow" 100 NORMAL-MODE)))
  77.          (bumpmap (car (gimp-layer-new img size size RGB-IMAGE "Bumpmap" 100 NORMAL-MODE)))
  78.          (big-arrow (point-list->double-array (rotate-points (make-arrow size 6) size orientation)))
  79.          (med-arrow (point-list->double-array (rotate-points (make-arrow size 7) size orientation)))
  80.          (small-arrow (point-list->double-array (rotate-points (make-arrow size 8) size orientation))))
  81.  
  82.     (gimp-context-push)
  83.  
  84.     (gimp-image-undo-disable img)
  85.     (gimp-image-add-layer img background -1)
  86.     (gimp-image-add-layer img bumpmap -1)
  87.  
  88.     ; Create pattern layer
  89.  
  90.     (gimp-context-set-background '(0 0 0))
  91.     (gimp-edit-fill background BACKGROUND-FILL)
  92.     (gimp-context-set-pattern pattern)
  93.     (gimp-edit-bucket-fill background PATTERN-BUCKET-FILL NORMAL-MODE 100 0 FALSE 0 0)
  94.  
  95.     ; Create bumpmap layer
  96.  
  97.     (gimp-edit-fill bumpmap BACKGROUND-FILL)
  98.  
  99.     (gimp-context-set-background '(127 127 127))
  100.     (gimp-rect-select img 1 1 (- size 2) (- size 2) CHANNEL-OP-REPLACE FALSE 0)
  101.     (gimp-edit-fill bumpmap BACKGROUND-FILL)
  102.  
  103.     (gimp-context-set-background '(255 255 255))
  104.     (gimp-rect-select img 2 2 (- size 4) (- size 4) CHANNEL-OP-REPLACE FALSE 0)
  105.     (gimp-edit-fill bumpmap BACKGROUND-FILL)
  106.  
  107.     (gimp-context-set-background '(127 127 127))
  108.     (gimp-free-select img 6 big-arrow CHANNEL-OP-REPLACE TRUE FALSE 0)
  109.     (gimp-edit-fill bumpmap BACKGROUND-FILL)
  110.  
  111.     (gimp-context-set-background '(0 0 0))
  112.     (gimp-free-select img 6 med-arrow CHANNEL-OP-REPLACE TRUE FALSE 0)
  113.     (gimp-edit-fill bumpmap BACKGROUND-FILL)
  114.  
  115.     (gimp-selection-none img)
  116.  
  117.     ; Bumpmap
  118.  
  119.     (plug-in-bump-map 1 img background bumpmap 135 45 2 0 0 0 0 TRUE FALSE 0)
  120.  
  121.     ; Darken arrow
  122.  
  123.     (gimp-context-set-background '(255 255 255))
  124.     (gimp-edit-fill bumpmap BACKGROUND-FILL)
  125.  
  126.     (gimp-context-set-background '(192 192 192))
  127.     (gimp-free-select img 6 small-arrow CHANNEL-OP-REPLACE TRUE FALSE 0)
  128.     (gimp-edit-fill bumpmap BACKGROUND-FILL)
  129.  
  130.     (gimp-selection-none img)
  131.  
  132.     (gimp-layer-set-mode bumpmap MULTIPLY-MODE)
  133.  
  134.     (gimp-image-flatten img)
  135.  
  136.     (gimp-image-undo-enable img)
  137.     (gimp-display-new img)
  138.  
  139.     (gimp-context-pop)))
  140.  
  141.  
  142. (script-fu-register "script-fu-beveled-pattern-arrow"
  143.                     _"_Arrow..."
  144.                     "Beveled pattern arrow"
  145.                     "Federico Mena Quintero"
  146.                     "Federico Mena Quintero"
  147.                     "July 1997"
  148.                     ""
  149.                     SF-ADJUSTMENT _"Size"        '(32 5 150 1 10 0 1)
  150.                     SF-OPTION     _"Orientation" '(_"Right"
  151.                            _"Left"
  152.                            _"Up"
  153.                            _"Down")
  154.                     SF-PATTERN    _"Pattern"     "Wood")
  155.  
  156. (script-fu-menu-register "script-fu-beveled-pattern-arrow"
  157.              _"<Toolbox>/Xtns/Script-Fu/Web Page Themes/Beveled Pattern")
  158.